//
//  VReplaceVC.swift
//  TarBarJump
//
//  Created by 郑东喜 on 2017/1/9.
//  Copyright © 2017年 郑东喜. All rights reserved.
//

import UIKit
import WebKit

class VReplaceVC: BaseViewController {
  

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        
        url = mainIndexArray.lastObject as! String
        
        let url1 = URL.init(string: url)
        
        
        self.urlRequestCache = NSURLRequest.init(url: url1!)
        
        self.webView.load(self.urlRequestCache as URLRequest)
    }
    
    
    override func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
        url = (navigationAction.request.url?.absoluteString)!

        
        print(url)
        
        if navigationAction.navigationType == WKNavigationType.linkActivated {
            
            print(mainIndexArray)
            
            
            mainIndexArray.add(self.url)
            self.aaa(str: mainIndexArray.lastObject as! String)
            
            decisionHandler(.cancel)
            
        } else {
            decisionHandler(.allow)
        }
    }
    
    //url---
    func aaa(str : String) -> Void {
        
        let vvv = ViewController2()
        vvv.url = str
        
        self.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(vvv, animated: true)
        self.hidesBottomBarWhenPushed = false
        
    }


}
